<?php
namespace app\model;
use think\Model;

class Wages extends Model
{
    

    public function getInfoByWorkNum($num){
        try {
            $data = $this->where('work_num',$num)->find();
            return [true,$data];
            //code...
        } catch (\Exception $e) {
            return [false,$e->getMessage()];
        }
    }

    public function getStaffWages($num){
        try {
            $data = $this->where('work_num',$num)->find();
            return [true,$data];
            //code...
        } catch (\Exception $e) {
            return [false,$e->getMessage()];
        }
    }
    
    public function getAll($list_rows,bool $simple = false,$config,$post){
        $select_post = array_diff_key ( $post, ['list_rows'=>-1,'page'=>-1] );
        try {
            $data = $this->where($select_post)->paginate($list_rows,$simple,$config)->toArray();
            return [true,$data];
            //code...
        } catch (\Exception $e) {
            return [false,$e->getMessage()];
        }
    }

    public function getAllWorkNum(){
        try {
            $data = $this->withAttr('work_num')->select();
            return [true,$data];
            //code...
        } catch (\Exception $e) {
            return [false,$e->getMessage()];
            //throw $th;
        }
    }

    public function updateRoles($num,$roles){
        try {
            $roles = 6 - $roles;
            $data = $this->where('work_num', $num)->update(['roles' => $roles]);
            return [true,$data];
            //code...
        } catch (\Exception $e) {
            return [false,$e->getMessage()];
            //throw $th;
        }
    }

    public function updateWages($name,$keyname,$wages){
        try {
            // return $status;
            $data = $this->where('name', $name)->update([$keyname => $wages]);
            return [true,$data];
            //code...
        } catch (\Exception $e) {
            return [false,$e->getMessage()];
            //throw $th;
        }
    }
}
